/*
 * DialogProperties.java
 *
 * Created on November 19, 2008, 2:55 PM
 */

package ca.jerg.canvas;

import ca.jerg.config.ErgConfigCanvas;
import ca.jerg.config.IErgConfig;
import java.awt.Color;

/**
 *
 * @author  dave
 */
public class DialogProperties extends javax.swing.JPanel {

    /** Creates new form DialogProperties */
    public DialogProperties() {
        initComponents();
    }

	public DialogProperties( ErgConfigCanvas defaults )
	{
		initComponents();
		setDefaults(defaults);
	}
	
	public DialogProperties( int xTick, int yTick, boolean grids,
			double lineWidth, Color lineColour,
			int pointRadius, Color pointColour )
	{
		initComponents();
		setXTick(xTick);
		setYTick(yTick);
		setGridLines(grids);
		setLineWidth(lineWidth);
		setLineColour(lineColour);
		setPointRadius(pointRadius);
		setPointColour(pointColour);
	}	
	
	// <editor-fold defaultstate="collapsed" desc="Accessors">
	public void setDefaults( ErgConfigCanvas defaults )
	{
		setXTick((int)defaults.getDouble(IErgConfig.KEY_X_AXIS_TICK_SPACE,ErgConfigCanvas.DEF_X_AXIS_TICK_SPACE));
		setYTick((int)defaults.getDouble(IErgConfig.KEY_Y_AXIS_TICK_SPACE,ErgConfigCanvas.DEF_Y_AXIS_TICK_SPACE));
		setGridLines(defaults.getBoolean(IErgConfig.KEY_SHOW_GRIDS,ErgConfigCanvas.DEF_SHOW_GRIDS));
		setLineWidth(defaults.getDouble(IErgConfig.KEY_DATA_LINE_WIDTH,ErgConfigCanvas.DEF_DATA_LINE_WIDTH));
		setLineColour(new Color(defaults.getInt(IErgConfig.KEY_DATA_LINE_COLOUR, 
				ErgConfigCanvas.DEF_DATA_LINE_COLOUR.getRGB())));
		setPointRadius(defaults.getInt(IErgConfig.KEY_DATA_POINT_RADIUS,ErgConfigCanvas.DEF_DATA_POINT_RADIUS));
		setPointColour(new Color(defaults.getInt(IErgConfig.KEY_DATA_POINT_COLOUR, 
				ErgConfigCanvas.DEF_DATA_POINT_COLOUR.getRGB())));
	}
	
	public void setXTick( int size )
	{
		xAxisTick.setText(String.valueOf(size));
	}
	
	public int getXTick()
	{
		return Integer.parseInt(xAxisTick.getText());
	}

	public void setYTick( int size )
	{
		yAxisTick.setText(String.valueOf(size));
	}
	
	public int getYTick()
	{
		return Integer.parseInt(yAxisTick.getText());
	}
	
	public void setGridLines( boolean set )
	{
		gridLines.setSelected(set);
	}
	
	public boolean getGridLines()
	{
		return gridLines.isSelected();
	}
	
	public void setLineWidth( double width )
	{
		lineWidth.setValue((int)(width * 100));
	}
	
	public int getLineWidth()
	{
		return lineWidth.getValue() / 100;
	}
	
	public void setPointRadius( int radius )
	{
		pointRadius.setValue(radius);
	}
	
	public int getPointRadius()
	{
		return pointRadius.getValue();
	}
	
	public Color getLineColour()
	{
		return lineColour.getColor();
	}
	
	public void setLineColour( Color c )
	{
		lineColour.setColor(c);
	}
	
	public Color getPointColour()
	{
		return pointColour.getColor();
	}
	
	public void setPointColour( Color c )
	{
		pointColour.setColor(c);
	}	
	// </editor-fold>
	
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        xAxisTick = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        yAxisTick = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        gridLines = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        lineWidth = new javax.swing.JSlider();
        jLabel6 = new javax.swing.JLabel();
        lineColour = new net.java.dev.colorchooser.ColorChooser();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        pointRadius = new javax.swing.JSlider();
        jLabel8 = new javax.swing.JLabel();
        pointColour = new net.java.dev.colorchooser.ColorChooser();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ticks & Grids"));

        jLabel1.setText("Place a X axis tick every");

        xAxisTick.setColumns(3);
        xAxisTick.setText("jTextField1");

        jLabel2.setText("minutes");

        jLabel3.setText("Place a Y axis tick every");

        yAxisTick.setColumns(3);
        yAxisTick.setText("jTextField1");

        jLabel4.setText("watts");

        gridLines.setText("Draw grid lines");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(xAxisTick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(yAxisTick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel4))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(gridLines)))
                .addContainerGap(60, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(xAxisTick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(yAxisTick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addComponent(gridLines)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Lines"));
        jPanel2.setLayout(new java.awt.GridLayout(2, 2));

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Width");
        jPanel2.add(jLabel5);

        lineWidth.setMaximum(200);
        jPanel2.add(lineWidth);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Colour");
        jPanel2.add(jLabel6);

        javax.swing.GroupLayout lineColourLayout = new javax.swing.GroupLayout(lineColour);
        lineColour.setLayout(lineColourLayout);
        lineColourLayout.setHorizontalGroup(
            lineColourLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 172, Short.MAX_VALUE)
        );
        lineColourLayout.setVerticalGroup(
            lineColourLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );

        jPanel2.add(lineColour);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Points"));
        jPanel3.setLayout(new java.awt.GridLayout(2, 2));

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Radius");
        jPanel3.add(jLabel7);

        pointRadius.setMaximum(10);
        pointRadius.setPaintLabels(true);
        jPanel3.add(pointRadius);

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Colour");
        jPanel3.add(jLabel8);

        javax.swing.GroupLayout pointColourLayout = new javax.swing.GroupLayout(pointColour);
        pointColour.setLayout(pointColourLayout);
        pointColourLayout.setHorizontalGroup(
            pointColourLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 172, Short.MAX_VALUE)
        );
        pointColourLayout.setVerticalGroup(
            pointColourLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 23, Short.MAX_VALUE)
        );

        jPanel3.add(pointColour);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox gridLines;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private net.java.dev.colorchooser.ColorChooser lineColour;
    private javax.swing.JSlider lineWidth;
    private net.java.dev.colorchooser.ColorChooser pointColour;
    private javax.swing.JSlider pointRadius;
    private javax.swing.JTextField xAxisTick;
    private javax.swing.JTextField yAxisTick;
    // End of variables declaration//GEN-END:variables

}
